﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HumanWorkflow.TextualDslParser.IronyParser;
using Irony.Parsing;

namespace HumanWorkflow.TextualDslParserTest
{
    [TestClass]
    public class HwdlGrammarTest
    {
        [TestMethod]
        public void HumanWorkflowParser_OrderWorkflowParsingTest()
        {
            string orderWorkflowDef = @"
workflow OrderWorkflow
	{
		roles
		{
			CustomerCare,
			Inventory
		}

		initial Start
		{
			goesto ConcordeCustomer when Start;
		}
		
		manual ConcordeCustomerData
		{
			goesto AreAllItemsOnStock when ConcordanceReady;
			doneby CustomerCare;
		}
		
		decision AreAllItemsOnStock
		{
			goesto ShipItems when AllItemsAreOnStock;
			goesto SendNotificationEmailToCustomer when ItemsAreMissing;	
		}

		automatic SendNotificationEmailToCustomer
		{
			goesto ShipItems when default;
		}

		manual ShipItems
		{
			goesto finish when ItemsShipped;
			doneby Inventory;
		}
						
	}
";

            HwdlGrammar grammar = new HwdlGrammar();
            Parser parser = new Parser(grammar);
            ParseTree rootNode = parser.Parse(orderWorkflowDef);

            string errorMessage = "";
            if (rootNode.HasErrors())
            {
                errorMessage = "Parsing failed with error: " + rootNode.ParserMessages.First<ParserMessage>().Message;
            }
            Assert.IsNotNull(rootNode.Root, errorMessage);
        }
    }
}
